001 /* 002 * Copyright 2006 Stephen McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package net.dpml.http; 017 018 /** 019 * Thread pool implementation. 020 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 021 * @version 0.0.0 022 */ 023 public class BoundedThreadPool extends org.mortbay.thread.BoundedThreadPool 024 { 025 /** 026 * HTTP Context handler context defintion. 027 */ 028 public interface Context 029 { 030 /** 031 * Get the minimum thread level. 032 * 033 * @param min the default minimum value 034 * @return the minimum thread level 035 */ 036 int getMin( int min ); 037 038 /** 039 * Return maximum thread level. 040 * 041 * @param max the default maximum value 042 * @return the maximum thread level 043 */ 044 int getMax( int max ); 045 046 /** 047 * Return the deamon flag. 048 * 049 * @param flag true if a damon thread 050 * @return the deamon thread policy 051 */ 052 boolean getDaemon( boolean flag ); 053 054 /** 055 * Get the thread pool name. 056 * 057 * @param name the pool name 058 * @return the name 059 */ 060 String getName( String name ); 061 062 /** 063 * Get the thread pool priority. 064 * 065 * @param priority the thread pool priority 066 * @return the priority 067 */ 068 int getPriority( int priority ); 069 070 /** 071 * Get the maximum idle time. 072 * 073 * @param idle the default maximum idle time 074 * @return the maximum idle time in milliseconds 075 */ 076 int getIdle( int idle ); 077 078 } 079 080 /** 081 * Creation of a new blocking thread pool. 082 * @param context the component context 083 * @exception Exception if an instantiation error occurs 084 */ 085 public BoundedThreadPool( Context context ) throws Exception 086 { 087 super(); 088 089 int min = context.getMin( 1 ); 090 int max = context.getMax( 255 ); 091 boolean daemon = context.getDaemon( true ); 092 String name = context.getName( "pool" ); 093 int priority = context.getPriority( Thread.NORM_PRIORITY ); 094 int idle = context.getIdle( 10000 ); 095 096 setMinThreads( min ); 097 setMaxThreads( max ); 098 setDaemon( daemon ); 099 setThreadsPriority( priority ); 100 setName( name ); 101 setMaxIdleTimeMs( idle ); 102 } 103 }